require('./PageApprovalsuggest.styl');
import { Control } from 'react-keeper';
const reactMixin = require('react-mixin');
const Actions = require('./actions');
const Store = require('./store');
const ui = require('clientConfig/util/jsapi/ui');
import Approvalsug from 'components/approvalsug'
const { Toast } = SaltUI;
class Approvalsuggest extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            loading: false
        };
    }
    getSuggest(suggest) {
        if(this.state.loading) {
            Toast.show({
                type: "error",
                content: "正在提交，请稍后"
            })
            return
        }
        this.setState({ loading: false }, () => {
            Actions.fetch(suggest)
        })
    }

    render() {
        return (
            <div className="approvalsuggest">
                <Approvalsug placeholder={this.state.placeholder} loading={this.state.loading} onsend={this.getSuggest.bind(this)} />
            </div>
        );
    }

    componentWillMount() {
        const index = Control.state.index;
        index == 0 && ui.setTitle({ title: '同意' });
        index == 1 && ui.setTitle({ title: '拒绝' });
        index == 2 && ui.setTitle({ title: '评论' });
    }

    componentDidMount() {
        const index = Control.state.index;
        var placeholder = '';
        index == 0 && (placeholder = "请输入同意理由（非必填）");
        index == 1 && (placeholder = "请输入拒绝理由");
        index == 2 && (placeholder = "说点什么吧...");
        this.setState({
            placeholder: placeholder
        })
    }

    componentWillReceiveProps(nextProps) {
    }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) {
    }

    componentDidUpdate(prevProps, prevState) {
    }

    componentWillUnmount() {
    }
}

reactMixin.onClass(Approvalsuggest, Reflux.connect(Store));

module.exports = Approvalsuggest;
